<?php

namespace backend\services\recharge;

use backend\extensions\ApiBaseService;
use backend\models\recharge\RechargeConfig;

/**
 * Desc 充值服务类
 * @author HUI
 */
class RechargeConfigService extends ApiBaseService
{

    /**
     * 列表
     * @param array $params 参数 
     * **/
    public static function getList($params)
    {
        //检索条件
        $condition = ['AND'];
        if ($params['name']) {
            $condition[] = ['like', 'name', $params['name']];
        }
        $list = RechargeConfig::getDataAll($condition, $params['page'], $params['page_size']);
        return $list;
    }

    /**
     * 新增
     * @param array $params 参数 
     * **/
    public static function create($params)
    {
        if (RechargeConfig::create($params) == false) {
            return self::jsonError('保存失败');
        }
        return self::jsonSuccess();
    }

    /**
     * 新增
     * @param array $params 参数 
     * **/
    public static function update($params)
    {
        $condition = ['id' => $params['id']];
        unset($params['id']);
        if (RechargeConfig::updateData($params, $condition) === false) {
            return self::jsonError('更新失败');
        }
        return self::jsonSuccess();
    }

    /**
     * 删除
     * @param array $params 参数 
     * **/
    public static function delete($params)
    {
        $condition = ['id' => $params['id']];
        if (RechargeConfig::del($condition) == false) {
            return self::jsonError('删除失败');
        }
        return self::jsonSuccess();
    }

    /**
     * 详情
     * @param array $params 参数 
     * **/
    public static function detail()
    {
        $condition = [];
        $data = RechargeConfig::getDataOne($condition, '', []);
        if($data){
            $data['config'] = json_decode($data['config'],320);
        }
        return self::jsonSuccess($data);
    }
}
